# Read CPI data
us_cpi <- read.csv("../Data/CPI Data/US Monthly CPI Base 1982.csv")
french_cpi <- read.csv("../Data/CPI Data/French Monthly CPI Base 2015.csv")
# Transform US data into proper format
# Initialize reference objects
months <- c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
row <- 1
us_cpi_long <- data.frame("year" = rep(us_cpi$Year, each = 12),
"month" = rep(months, times = nrow(us_cpi)),
"cpi" = rep(NA, length.out = nrow(us_cpi)*12))
for (i in 1:nrow(us_cpi)) {
for (j in 1:12) {
# Insert correct cpi value
us_cpi_long$cpi[row] <- us_cpi[i, (j + 1)]
# Increment row ticker
row <- row + 1
}
}
us_cpi_long <- head(us_cpi_long, -11) # remove final 11 rows (not real values)
us_cpi <- us_cpi_long # reassign to original object
rm(us_cpi_long) # eject intermediate object
# Normalize US Base year to 2000 January (originally Jul-1983)
new_base <- us_cpi$cpi[1045]
us_cpi$cpi <- us_cpi$cpi / new_base
# Subset US for 2000-2020
relevant_years <- 2000:2020
us_cpi <- us_cpi[us_cpi$year %in% relevant_years, ]
# Rename french cpi columns
colnames(french_cpi) <- c("date", "cpi")
# Normalize french base year to 2000 January (originally Jan-2015)
new_base <- french_cpi$cpi[76]
french_cpi$cpi <- french_cpi$cpi / new_base
# Subset french for 2000-2020
french_cpi$year <- substr(french_cpi$date, 1, 4) # create year column
french_cpi$year <- as.integer(french_cpi$year) # coerce to integer
french_cpi <- french_cpi[french_cpi$year %in% relevant_years, ]
# Merge into combined dataframe
years_vector <- rep(2000:2020, each = 12)
months_vector <- rep(months, times = 20)
cpi <- data.frame("date" = paste(years_vector, months_vector, sep = "-"),
"usa" = us_cpi$cpi,
"france" = french_cpi$cpi)
# Export csv
write.csv(cpi, "../Data/CPI Data/Merged CPI Base Jan 2000.csv", row.names = FALSE)
# Load packages
library(dplyr)
# Read data in
usa <- read.csv("../Data/Clean Data/USA Clean Data.csv")
france <- read.csv("../Data/Clean Data/France Clean Data.csv")
# Create year and month columns
usa$year <- substr(usa$issue_date, 1, 4)
usa$month <- substr(usa$issue_date, 6, 7)
france$year <- substr(france$issue_date, 1, 4)
france$month <- substr(france$issue_date, 6, 7)
# Subset for relevant years (2003-2013)
usa <- usa[usa$year %in% 2003:2013, ]
france <- france[france$year %in% 2003:2013, ]
# Aggregate monthly (using `dplyr`)
us_monthly <- usa %>%
group_by(year, month) %>%
summarise(
us_total_issue = sum(total_issue)
)
france_monthly <- france %>%
group_by(year, month) %>%
summarise(
france_total_issue = sum(total_issue)
)
# Merge into single dataframe
us_monthly <- as.data.frame(us_monthly)
france_monthly <- as.data.frame(france_monthly)
year_vector <- rep(2003:2013, each = 12)
months <- c("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12")
month_vector <- rep(months, times = 10)
by_month <- data.frame("date" = paste(year_vector, month_vector, sep = "-"),
"us_nominal" = us_monthly$us_total_issue,
"france_nominal" = france_monthly$france_total_issue)
# Export csv
write.csv(by_month, "../Data/Aggregated/Monthly Nominal 2003-2013.csv", row.names = FALSE)
# Read data
euro <- read.csv("../Data/EuroValue.csv")
by_month <- read.csv("../Data/Aggregated/Monthly Nominal 2003-2013.csv")
# Subset relevant euro
euro$year <- substr(euro$Date, 1, 4)
euro$year <- as.numeric(euro$year)
euro <- euro[euro$year %in% 2003:2013, 1:2]
# Add conversion column to data
by_month$euro_dollar <- euro$EuroDollar
# Add adjusted france nominal column
by_month$adj_france_nominal <- by_month$france_nominal*by_month$euro_dollar
# Export csv
write.csv(by_month, "../Data/Aggregated/Monthly Adjusted 2003-2013.csv", row.names = FALSE)
# Read data
by_month <- read.csv("../Data/Aggregated/Monthly Adjusted 2003-2013.csv")
cpi <- read.csv("../Data/CPI Data/Merged CPI Base Jan 2000.csv")
# Subset cpi to 2003-2013
cpi$year <- substr(cpi$date, 1, 4)
cpi$year <- as.numeric(cpi$year)
cpi <- cpi[cpi$year %in% 2003:2013, ]
cpi <- cpi[, -4]
# Add cpi columns to data
by_month$us_cpi <- cpi$usa
by_month$france_cpi <- cpi$france
# Add real issue columns to data
by_month$us_real <- by_month$us_nominal / by_month$us_cpi
by_month$france_real <- by_month$adj_france_nominal / by_month$france_cpi
# Export csv
write.csv(by_month, "../Data/Aggregated/Monthly Real 2003-2013.csv", row.names = FALSE)
# Read data
monthly <- read.csv("../Data/Aggregated/Monthly Real 2003-2013.csv")
# Separate pre- (2003-2006) and post- (2010-2013) treatment periods
monthly$year <- substr(monthly$date, 1, 4)
monthly$year <- as.integer(monthly$year)
pre_treatment <- monthly[monthly$year %in% 2003:2006, c(1, 8, 9)]
post_treatment <- monthly[monthly$year %in% 2010:2013, c(1, 8, 9)]
# Eject original object
rm(monthly)
# Separate Units
pre_treatment_france <- data.frame("date" = pre_treatment$date,
"period" = 0,
"treatment" = 0,
"real_issue" = pre_treatment$france_real)
post_treatment_france <- data.frame("date" = post_treatment$date,
"period" = 1,
"treatment" = 0,
"real_issue" = post_treatment$france_real)
pre_treatment_usa <- data.frame("date" = pre_treatment$date,
"period" = 0,
"treatment" = 1,
"real_issue" = pre_treatment$us_real)
post_treatment_usa <- data.frame("date" = post_treatment$date,
"period" = 1,
"treatment" = 1,
"real_issue" = post_treatment$us_real)
# Merge unit dataframes
did_monthly <- rbind(pre_treatment_france, post_treatment_france, pre_treatment_usa, post_treatment_usa)
# Eject intermediate objects
rm(pre_treatment,
post_treatment,
pre_treatment_france,
pre_treatment_usa,
post_treatment_france,
post_treatment_usa)
# Create period-treatment interaction binary
did_monthly$interaction <- did_monthly$period*did_monthly$treatment
# Regress
did_model <- lm(real_issue ~ treatment + period + interaction, data = did_monthly)
# Export model
save(did_model, file = "../Data/DiD Model.rds")
save(did_monthly, file = "../Data/DiD Monthly.rds")
View(euro)
View(did_monthly)
load("../Data/DiD Model.rds")
View(did_model)
summary(did_model)
did_summary <- summary(did_model)
did_summary$coefficients
typeof(did_summary$coefficients)
class(did_summary$coefficients)
load("../Data/DiD Model.rds")
did_summary <- summary(did_model)
load("../Data/DiD Model.rds")
did_summary <- summary(did_model)
did_coefficients <- did_summary$coefficients
round(did_coefficients[[1, 1]], 2)
?format
load("../Data/DiD Model.rds")
did_summary <- summary(did_model)
did_coefficients <- did_summary$coefficients
options(scipen = Inf)
did_summary
did_model$qr[df.residual]
did_model$qr[5[]
did_model$qr[5]
did_model$qr[5]
did_model$qr[4]
did_model$df.residual
view(did_summary)
did_summary
View(did_summary)
did_summary$df
did_summary$df[2]
did_summary$r.squared
load("../Data/DiD Model.rds")
did_summary <- summary(did_model)
did_coefficients <- did_summary$coefficients
did_summary
# United States Department of the Treasury
# Agence France Trésor
# United States Bureau of Labor Statistics
# Organisation for Economic Cooperation and Development
# United States Federal Reserve
load("../Data/DiD Model.rds")
did_summary <- summary(did_model)
did_coefficients <- did_summary$coefficients
did_summary
setwd("~/Dropbox/REPP/Final Paper")
load("../Data/DiD Model.rds")
did_summary <- summary(did_model)
did_coefficients <- did_summary$coefficients
did_coefficients[[4, 3]]
did_coefficients
str(did_summary)
did_summary$r.squared
load("../Data/DiD Model.rds")
did_summary <- summary(did_model)
did_coefficients <- did_summary$coefficients
did_summary
str(did_model)
str(summary(did_model))
summary(did_model)
stargazer(did_model)
library(stargazer)
stargazer(did_model)
str(did_model)
str(summary(did_model))
summary(did_model)$fstatistic
str(did_model)
summary(did_model)
str(summary(did_model))
str(did_model)
summary(did_model)
?nobs
nobs(did_model)
stargazer(did_model)
str(did_model)
str(summary(did_model))
citation()
load("../Data/DiD Model.rds")
did_summary <- summary(did_model)
did_coefficients <- did_summary$coefficients
did_summary
##### GLOBALS #####
# Load packages
library(mFilter)
# Read data
sp500 <- read.csv("../Data/Raw CSV/SP Data.csv") # S&P 500 Data
cpi <- read.csv("../Data/CPI Data/Merged CPI Base Jan 2000.csv") # cpi data
did_monthly <- read.csv("../Data/Monthly Issuance.csv") # monthly issuance
##### HP Analysis (S&P 500) #####
# Rename columns
colnames(sp500) <- c("date", "close_price")
# Extract year and month from date
sp500$year_month <- paste(substr(sp500$date, 7, 10), substr(sp500$date, 1, 2), sep = "-")
# Function to keep only the first observation of each month
keep_first_of_month <- function(df) {
df[!duplicated(df$year_month), ]
}
# Drop all observations which are not the first in a given month
sp500 <- keep_first_of_month(sp500)
# Clip `cpi` to relevant range
cpi <- head(cpi, 240)
# Deflate `sp500` series
sp500$adj_close_price <- sp500$close_price / cpi$usa
# Clip to relevant period (2003-2013)
sp500$year <- as.numeric(substr(sp500$date, 7, 10))
sp500 <- sp500[sp500$year %in% 2003:2013, ]
# Export
write.csv(sp500, "../Dataverse/Data/SP_500.csv", row.names=FALSE)
setwd("~/Dropbox/REPP/Dataverse")
##### GLOBALS #####
# Load packages
library(mFilter)
# Read data
sp500 <- read.csv("Data/SP_500.csv") # S&P 500 Data
tb_issuance <- read.csv("Data/TB_Issuance.csv") # monthly issuance
##### HP Analysis (S&P 500) #####
# HP Filters
sp500$ru_smoothed <- hpfilter(sp500$adj_close_price, # data
type = "lambda", # use lambda method
freq = 123600)$ trend # extract trend at lambda = 123600
sp500$hp_smoothed <- hpfilter(sp500$adj_close_price, # data
type = "lambda", # use lambda method
freq = 14400)$trend # extract trend at lambda = 14400
# Add Time index
sp500$time_index <- seq_along(sp500$date)
# Plot
plot(x = sp500$time_index,
y = sp500$adj_close_price,
col = "red",
type = "l",
ylab = "Price (USD)",
xlab = "Time",
main = "Inflation-Adjusted S&P 500",
xaxt = "n",
ylim = c(0, 2500))
# Add HP line
lines(x = sp500$time_index,
y = sp500$hp_smoothed,
col = "blue",
lty = 1)
# Add RU line
lines(x = sp500$time_index,
y = sp500$ru_smoothed,
col = "forestgreen",
lty = 1)
# Add legend
legend(x = "topleft",
inset = 0.01,
legend = c("Data","λ = 14,400","λ = 123,600"),
fill = c("red", "blue", "forestgreen"))
##### HP Analysis (Treasury) #####
# Subset by country (US Only)
us_tbi <- tb_issuance[tb_issuance$treatment == 1, ]
# Create index column
us_tbi$index <- 1:nrow(us_tbi)
# Adjust into billions
us_tbi$real_issue <- us_tbi$real_issue / 1000
# Create HP filters
us_tbi$ru_smoothed <- hpfilter(us_tbi$real_issue, # data
type = "lambda", # use lambda method
freq = 123600)$ trend # extract trend at lambda = 123600
us_tbi$hp_smoothed <- hpfilter(us_tbi$real_issue, # data
type = "lambda", # use lambda method
freq = 14400)$trend # extract trend at lambda = 14400
# Plot
plot(x = us_tbi$index,
y = us_tbi$real_issue,
col = "red",
type = "l",
ylab = "Issuance (Billions of USD)",
xlab = "Time",
main = "US Real Monthly Treasury Auctions",
xaxt = "n",
ylim = c(100, 600))
# Add HP line
lines(us_tbi$index,
us_tbi$hp_smoothed,
col = "blue")
# Add RU line
lines(us_tbi$index,
us_tbi$ru_smoothed,
col = "forestgreen")
# Add legend
legend(x = "topleft",
inset = 0.01,
legend = c("Data","λ = 14,400","λ = 123,600"),
fill = c("red", "blue", "forestgreen"))
##### DiD Model #####
did_model <- lm(real_issue ~
treatment +
period +
interaction,
data = tb_issuance)
##### GLOBALS #####
# Load packages
library(mFilter)
# Read data
sp500 <- read.csv("Data/SP_500.csv") # S&P 500 Data
tb_issuance <- read.csv("Data/TB_Issuance.csv") # monthly issuance
##### HP Analysis (S&P 500) #####
# HP Filters
sp500$ru_smoothed <- hpfilter(sp500$adj_close_price, # data
type = "lambda", # use lambda method
freq = 123600)$ trend # extract trend at lambda = 123600
sp500$hp_smoothed <- hpfilter(sp500$adj_close_price, # data
type = "lambda", # use lambda method
freq = 14400)$trend # extract trend at lambda = 14400
# Add Time index
sp500$time_index <- seq_along(sp500$date)
# Plot
plot(x = sp500$time_index,
y = sp500$adj_close_price,
col = "red",
type = "l",
ylab = "Price (USD)",
xlab = "Time",
main = "Inflation-Adjusted S&P 500",
xaxt = "n",
ylim = c(0, 2500))
# Add HP line
lines(x = sp500$time_index,
y = sp500$hp_smoothed,
col = "blue",
lty = 1)
# Add RU line
lines(x = sp500$time_index,
y = sp500$ru_smoothed,
col = "forestgreen",
lty = 1)
# Add legend
legend(x = "topleft",
inset = 0.01,
legend = c("Data","λ = 14,400","λ = 123,600"),
fill = c("red", "blue", "forestgreen"))
##### HP Analysis (Treasury) #####
# Subset by country (US Only)
us_tbi <- tb_issuance[tb_issuance$treatment == 1, ]
# Create index column
us_tbi$index <- 1:nrow(us_tbi)
# Adjust into billions
us_tbi$real_issue <- us_tbi$real_issue / 1000
# Create HP filters
us_tbi$ru_smoothed <- hpfilter(us_tbi$real_issue, # data
type = "lambda", # use lambda method
freq = 123600)$ trend # extract trend at lambda = 123600
us_tbi$hp_smoothed <- hpfilter(us_tbi$real_issue, # data
type = "lambda", # use lambda method
freq = 14400)$trend # extract trend at lambda = 14400
# Plot
plot(x = us_tbi$index,
y = us_tbi$real_issue,
col = "red",
type = "l",
ylab = "Issuance (Billions of USD)",
xlab = "Time",
main = "US Real Monthly Treasury Auctions",
xaxt = "n",
ylim = c(100, 600))
# Add HP line
lines(us_tbi$index,
us_tbi$hp_smoothed,
col = "blue")
# Add RU line
lines(us_tbi$index,
us_tbi$ru_smoothed,
col = "forestgreen")
# Add legend
legend(x = "topleft",
inset = 0.01,
legend = c("Data","λ = 14,400","λ = 123,600"),
fill = c("red", "blue", "forestgreen"))
##### DiD Model #####
did_model <- lm(real_issue ~
treatment +
period +
interaction,
data = tb_issuance)
##### GLOBALS #####
# Load packages
library(mFilter)
# Read data
sp500 <- read.csv("SP_500.csv") # S&P 500 Data
tb_issuance <- read.csv("TB_Issuance.csv") # Monthly TB Issuance Data
##### HP Analysis (S&P 500) #####
# HP Filters
sp500$ru_smoothed <- hpfilter(sp500$adj_close_price, # data
type = "lambda", # use lambda method
freq = 123600)$ trend # extract trend at lambda = 123600
sp500$hp_smoothed <- hpfilter(sp500$adj_close_price, # data
type = "lambda", # use lambda method
freq = 14400)$trend # extract trend at lambda = 14400
# Add Time index
sp500$time_index <- seq_along(sp500$date)
# Plot
plot(x = sp500$time_index,
y = sp500$adj_close_price,
col = "red",
type = "l",
ylab = "Price (USD)",
xlab = "Time",
main = "Inflation-Adjusted S&P 500",
xaxt = "n",
ylim = c(0, 2500))
# Add HP line
lines(x = sp500$time_index,
y = sp500$hp_smoothed,
col = "blue",
lty = 1)
# Add RU line
lines(x = sp500$time_index,
y = sp500$ru_smoothed,
col = "forestgreen",
lty = 1)
# Add legend
legend(x = "topleft",
inset = 0.01,
legend = c("Data","λ = 14,400","λ = 123,600"),
fill = c("red", "blue", "forestgreen"))
##### HP Analysis (Treasury) #####
# Subset by country (US Only)
us_tbi <- tb_issuance[tb_issuance$treatment == 1, ]
# Create index column
us_tbi$index <- 1:nrow(us_tbi)
# Adjust into billions
us_tbi$real_issue <- us_tbi$real_issue / 1000
# Create HP filters
us_tbi$ru_smoothed <- hpfilter(us_tbi$real_issue, # data
type = "lambda", # use lambda method
freq = 123600)$ trend # extract trend at lambda = 123600
us_tbi$hp_smoothed <- hpfilter(us_tbi$real_issue, # data
type = "lambda", # use lambda method
freq = 14400)$trend # extract trend at lambda = 14400
# Plot
plot(x = us_tbi$index,
y = us_tbi$real_issue,
col = "red",
type = "l",
ylab = "Issuance (Billions of USD)",
xlab = "Time",
main = "US Real Monthly Treasury Auctions",
xaxt = "n",
ylim = c(100, 600))
# Add HP line
lines(us_tbi$index,
us_tbi$hp_smoothed,
col = "blue")
# Add RU line
lines(us_tbi$index,
us_tbi$ru_smoothed,
col = "forestgreen")
# Add legend
legend(x = "topleft",
inset = 0.01,
legend = c("Data","λ = 14,400","λ = 123,600"),
fill = c("red", "blue", "forestgreen"))
##### DiD Model #####
did_model <- lm(real_issue ~
treatment +
period +
interaction,
data = tb_issuance)
